1. Technical Field
The present invention is directed to a method, system, and program for efficient send socket call handling by a transport layer, wherein the send socket call is blocked until sufficient memory is available for a single memory allocation within the socket buffer sufficient for an entire length of data in said send socket call.
2. Description of Related Art
The Internet has become a significant communication media in the modern world and is enabling the world to migrate to one global data communications system. In general, the Internet uses the Transmission Control Protocol/Internet Protocol (TCP/IP) suit of protocols to provide a common communication mechanism for computers, and other data transmission devices, to communicate with one another.
Communication with applications running on a server is typically performed using ports and addresses assigned to the application and the server apparatus. A port may be a physical port or a logical port. A physical port is a pathway into and out of a computer or a network device such as a switch or router. For example, the serial and parallel ports on a personal computer are external sockets for plugging in communication lines, modems, and printers. Every network adapter has a port (Ethernet, Token Ring, etc.) for connection to the local area network (LAN). Any device that transmits and receives data implies an available port to connect to each line.
A logical port is a number assigned to an application running on the server by which the application can be identified. While a server may have a single physical port, the server may use multiple logical ports. The combination, of a logical port identifier and the address of the server apparatus, is referred to as a socket.
The address of a server is a network address that identifies the server in the network and how to route data to a particular physical port of the server through the network. The address may take the form of a Uniform Resource Locator (URL), or in the case of the Internet, an Internet Protocol (IP) address such as 205.15.01.01, or the like. The address is included in headers of data packets transmitted by a device. The data packets are routed through the network from device to device by reading the header of the data packet and determining how to route the data packet to its intended destination based on the address.
The TCP/IP protocol provides various socket functions that may be used in the handing of data as the data is transported to and from the application through the socket. One such function that is used by an application for a write request is the send socket call. For example, an application invokes a send socket call and specifies the socket, buffer within the socket, length of the data to be sent, and set flags. The TCP layer of the TCP/IP protocol stack receives the send socket call and triggers the kernel to allocate available memory to a send buffer within the socket for writing the send socket call data. In particular, a pool of memory is available for allocation to sockets, where each allocation is termed an mbuf. In some cases, there is sufficient memory available to allocate a single mbuf that is large enough for the length of the send function data. However, If not all the data can be written to the first mbuf or if no memory is available for allocation of an mbuf when the send function is received, then the TCP blocks the send thread.
As the TCP layer receives acknowledgements (ACKs) that sent data packets are received by the receiver, the TCP layer calls the kernel to release the acknowledged data packets back into the pool of memory. In addition, for each ACK, the TCP wakes up the blocked send thread, which then triggers the kernel to attempt to allocate an mbuf from the recently released memory into the send buffer and to write the next portion of the data to the new mbuf.
In one example, a send socket call sets the length of the data to at 64 kilobytes. Each data packet sent by the TCP layer to the receiver is limited to a maximum segment size (MSS) of 1460 bytes and each ACK is 2 MSS, or 2920 bytes (4 kilobytes). When the TCP layer receives the send socket call, in the example, there is 4 k of memory available for allocation to the send buffer for the socket. The kernel allocates a 4 k mbuf to the send buffer and writes 4 k of the 64 k of data into the send buffer, leaving 60 k of data remaining to be written. The TCP layer then blocks the send thread until a next ACK is received. When the TCP layer receives the next ACK, the TCP layer triggers the kernel to release the mbuf holding the data associated with the ACK. Next, the TCP layer wakes up the send thread which triggers the kernel to attempt to allocate a new mbuf from the released memory and write another 4 k into the new mbuf. Thus, for a 64 k send socket call where the ACKs are slow to return, in the example, the TCP layer may block and wake up the send thread 16 or more times.
As indicated by the example, while the single send socket call for a large data write is efficient for an application sending the data, the single send socket call is not handled efficiently within the TCP/IP protocol stack when the data length is larger than the memory available for allocation. In particular, for the TCP layer to handle the send thread by blocking when no additional memory is available for allocation and then waking up the thread each time an ACK is received, significant CPU, bus and memory resources are inefficiently locked up and only a portion of the data is written for each wake up.
Further, as the TCP layer inefficiently triggers a separate mbuf allocation each time an ACK is received and memory is released, each mbuf is added to a chain. As the mbuf chain increases, locating an mbuf to release memory becomes more time consuming and thus inefficient. In addition, when the data for a single send socket call is written to multiple chained mbufs, to push the data to the network, the TCP layer must pass multiple pointers to the chained mbufs to a network layer and link layer. For the link layer, which includes the adapter hardware for actually placing the data packet onto the network, a direct memory access (DMA) is made to the data from the pointers passed down by the TCP layer and the data queued at the adapter level; it is inefficient, however, to perform a direct memory access (DMA) of the pointed to chained mbufs because the adapter only queues contiguous data and thus additional memory management is required to copy the chained mbufs into contiguous data.
Therefore, in view of the foregoing, it would be beneficial to enable a transport layer to respond to a send socket call such that when the memory pool does not include sufficient memory available for allocation to an mbuf large enough for the send socket call length, the transport layer blocks the send thread until sufficient memory is available for allocation of a single mbuf for writing the data in one pass for the send socket call.